﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

namespace BSC_SERVICES.Code
{
    public class ReadErrorDesc
    {
        #region khai bao bien
        Connect_DataBase _db = new Connect_DataBase();
        #endregion


        // get all bsc_deferror
        public DataTable Get_All_bsc_deferror()
        {
            return _db.Return_Datatable("select * from bsc_deferror");
        }

        public DataTable Get_All_bsc_deferror_tablename(string _tablename)
        {
            return _db.Return_Datatable("select * from bsc_deferror where modcode like '"+_tablename+"'");
        }

        // Get error by error_num
        public string Get_error_by_message(string _message, string _tableName)
        {
            DataTable tableError = this.Get_All_bsc_deferror_tablename(_tableName);
            foreach (DataRow row in tableError.Rows)
            {
                if (_message.Contains(Convert.ToString(row["errnum"])))
                {
                    if (Convert.ToString(row["errkeyword"]) != "")
                    {
                        if (_message.Contains (Convert.ToString(row["errkeyword"])))
                        {
                             return Convert.ToString(row["errdesc"]);
                        }
                    }
                    return Convert.ToString(row["errdesc"]);
                }
            }
            return CL_Ultility.messeseboxMaSuKienKhongTonTai;
        }

        // Get error by error_num and mod_code
        //public DataTable Get_All_bsc_deferror()
        //{
        //    this._db.OpenConnect();
        //    return _db.Return_Datatable("select * from bsc_deferror");
        //}
    }
}